package com.example.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.model.auto.CompanyInfo;
import com.example.service.ICompanyInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 姚帅
 * @since 
 */
@RestController
@RequestMapping("/company")
public class CompanyInfoController {

    @Autowired
    private ICompanyInfoService iCompanyInfoService;

    /*查询资讯分类*/
    @GetMapping("/getCompany")
    public List<CompanyInfo> getCompany(){
        return iCompanyInfoService.list();
    }

    /*通过id查询资讯分类*/
    @GetMapping("/getCompanyById/{id}")
    public CompanyInfo getCompanyById(@PathVariable("id") int id){
        return iCompanyInfoService.getById(id);
    }

    /*修改资讯分类*/
    @PostMapping("/updateCompany")
    public void updateCompany(@RequestBody CompanyInfo companyInfo){
        iCompanyInfoService.updateById(companyInfo);
    }

    /*添加资讯分类*/
    @PostMapping("/setCompany")
    public void setCompany(@RequestBody CompanyInfo companyInfo){
        iCompanyInfoService.save(companyInfo);
    }

    /*删除资讯分类*/
    @PostMapping("/deletedById/{id}")
    public boolean deleted(@PathVariable("id") int id){
        return iCompanyInfoService.removeById(id);
    }

    /*模糊查询资讯分类数据*/
    @PostMapping("/selectInfo/{title}")
    public List<Map<String, Object>> selectInfo(@PathVariable("title") String value){
        System.out.println(value);
        QueryWrapper<CompanyInfo> queryWrapper = new QueryWrapper<>();
        /*核心模糊算法*/
        queryWrapper.like("name",value).or().like("boss",value).or().like("adress",value)
                .or().like("money",value)
                .or().like("phone",value);
        List<Map<String, Object>> maps = iCompanyInfoService.listMaps(queryWrapper);
        return maps;
    }


}
